#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
    //declaring stuff
    HANDLE thy_p,tkh;
    LUID thy_l;
    TOKEN_PRIVILEGES t_p;
    LPCVOID lpaddr = 0;
    LPCSTR
    int cbuf;
    DWORD sobuf;
    MEMORY_BASIC_INFORMATION mbi;
    SYSTEM_INFO si;
    int vqex_r;
    //end declarations
    thy_p = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 5656);//PID
    //Start token stuff
    if (OpenProcessToken(thy_p, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &tkh) == 0) {
       cout << "OpenProcessToken Error        " << GetLastError() << endl;
       system("pause");
       return 0;
       }
    if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &thy_l) == 0) {
       cout << "LookupPrivilegeValue Error        " << GetLastError() << endl;
       system("pause");
       return 0;
       }
    // Error is found right here!!!
    cout << "LUT " << GetLastError() << endl;
    t_p.PrivilegeCount = 1;//setting class things
    t_p.Privileges[0].Luid = thy_l;
    t_p.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    if (AdjustTokenPrivileges(tkh, FALSE, &t_p, 0, NULL, NULL) == 0) {
       cout << "AdjustTokenPrivileges Error        " << GetLastError() << endl;
       system("pause");
       return 0;
       }
    cout << "ATP " << GetLastError() << endl;
    //End token stuff
    GetSystemInfo(&si);
    //while (lpaddr < si.lpMaximumApplicationAddress) {
          vqex_r = VirtualQueryEx(thy_p, lpaddr, &mbi, sizeof(mbi) );
          lpaddr = (LPCVOID)((DWORD)mbi.BaseAddress + (DWORD)mbi.RegionSize);
          ReadProcessMemory(thy_p, &lpaddr, (void*)cbuf, sizeof(cbuf), &sobuf);
          cout << lpaddr << "        " << cbuf << "     " << sobuf << endl;
    //}
    CloseHandle(tkh);
    system("pause");
    return 0;
}
